<?php
/* @var $this PartyController */
/* @var $model Party */

//设置页面标题
$this->pageTitle=Yii::app()->name.' - [用户]列表';
$this->contentTitle='[用户]列表';
?>
<!-- 查询表单 -->
<?php $this->renderPartial('_search_clander',array(
	'model'=>$model,
)); ?>
<!-- 查询表单 -->

<!-- 数据表格 -->
<table cellspacing="1" class="mylist2">
		<tr class="mylist_title">
			<td width="3%"><input type="checkbox" class="checkbox" onclick="InverSelect();" /></td>
			<td><?php echo CHtml::encode($model->getAttributeLabel('id')); ?></td>
                        <td><?php echo CHtml::encode($model->getAttributeLabel('user_code')); ?></td>
                        <td><?php echo CHtml::encode($model->getAttributeLabel('crowd_id')); ?></td>
			<td><?php echo CHtml::encode($model->getAttributeLabel('username')); ?></td>
			<td><?php echo CHtml::encode($model->getAttributeLabel('phone')); ?></td>
			<td><?php echo CHtml::encode($model->getAttributeLabel('sex')); ?></td>
                        <td>是否有儿童</td>
                        <td><?php echo CHtml::encode($model->getAttributeLabel('address')); ?></td>
			<td><?php echo CHtml::encode($model->getAttributeLabel('company')); ?></td>
			<td><?php echo CHtml::encode($model->getAttributeLabel('recommend')); ?></td>
                        <td><?php echo CHtml::encode($model->getAttributeLabel('head_image')); ?></td>
			<td><?php echo CHtml::encode($model->getAttributeLabel('is_from')); ?></td>
                        <td>黑名单操作</td>
                        <td>友情提示</td>
                        <td>发送状态</td>
                        <td>审核状态</td>
		</tr>
	<tbody>
		<?php
                $ad_id=0;
                foreach ($data->getData() as $key => $value) {
                    $ad_id=$value->ad_id;
                ?>
		<tr class="datalist">
			<td align="center"><input name="id[]" type="checkbox" value="<?php echo CHtml::encode($value->id); ?>" class="checkbox" /></td>
                        <td><?php echo CHtml::encode($value->id);?></td>
                        <td><?php echo CHtml::encode($value->user_code);?></td>
                        <td><?php echo CHtml::encode($value->crowd->title);?></td>
			<td><?php echo CHtml::link($value->username, array('party/update','id'=>$value->id,'type'=>'party'),array('target'=>'_parent')); ?></td>
			<td><?php echo CHtml::encode($value->phone);?></td>
			<td><?php echo CHtml::encode($value->sex);?></td>
                        <td>
                        <?php 
                            $cmodels=Children::model()->findAll("party_id=".$value->id);
                            $c_count=  count($cmodels);
                            if($c_count>0){
                                echo '<a target="_parent" href="/ex/sign/index.php/party/update?type=clander&id='.$value->id.'">'.$c_count.'</a>';
                            }  else {
                                echo '0';
                            }
                        ?>
                        </td>
			<td><?php echo CHtml::encode($value->address);?></td>
			<td><?php echo CHtml::encode($value->company);?></td>
			<td><?php echo CHtml::encode($value->recommend);?></td>
                        <td align="center">
                            <?php 
                                $images='';
                                if(!empty($value->head_image))
                                    $images=$value->head_image;
                                else
                                    $images=Yii::app()->baseUrl.'/images/wu.png';
                            ?>
                            <img width="50px" height="50px" src="<?php echo $images?>"></td>
<!--                        <td><?php echo CHtml::encode(Ccommon::ctype($value->is_from));?></td>-->
                        <td><?php 
                            if($value->is_from==0){
                                echo CHtml::link('未来', 'javascript:notTo('.$value->id.');');
                            }elseif ($value->is_from==1) {
                                echo CHtml::link('已来', 'javascript:haveTo('.$value->id.');');    
                            }  else {
                                echo CHtml::link('已取消', 'javascript:cancelTo('.$value->id.');');  
                            }
                        ?></td>
                        <td align="center"><?php
                            $count=Blacklist::model()->count("phone='".$value->phone."' and code='".$value->code."'");
                            if($count<=0){
                                 echo CHtml::link('拉黑', 'javascript:updateSelect('.$value->id.');');
                               
                            }else{
                                 echo CHtml::link('取消拉黑', 'javascript:canceSelect('.$value->id.');');
                            }
                            ?>
                        </td>
		    
                    <td align="center" class="action">
                         <?php 
                         if($value->is_float!=0){}
                            echo CHtml::link('点击发送', 'javascript:sendSelect('.$value->id.');');
                          ?>
                    </td>
                     <td align="center" class="action">
                          <?php 
                            if($value->is_send==0){
                                echo '待发送';
                            }else{
                                 echo '已发送';
                            }
                          ?>
                    </td>
                     <td align="center" class="action">
                        <?php 
                                if($value->is_float==0){
                                    echo CHtml::link('审核通过', 'javascript:floatSelect('.$value->id.');');
                                }else{
                                    echo CHtml::link('已审核', 'javascript:floatSelect('.$value->id.');',array('style'=>'color:green'));
                                }
                        ?>
                    </td>
                   
		</tr>
		<?php }?>

	</tbody>
</table>
<!-- 数据表格 -->

<!-- 数据分页 -->
<div class="mylist_foot">
    <div class="fl p10 btn"><a href="javascript:sendSelect(0);">批量发送短信</a></div>
    <div class="fl p10 btn"><a href="javascript:updateSelect(0);">批 量 拉 黑</a></div>
    <div class="fl p10 btn"><a target="_parent" href="<?php echo Yii::app()->baseUrl?>/index.php/party/create?type=clander&ad_id=<?php echo $ad_id;?>">添加</a></div>
</div>
	<div class="pagecss fr">
	<?php $this->widget("CLinkPager", array(
        "pages" => $data->pagination,
        "header"=>"跳转到：",
        "prevPageLabel"=>"&lt; 上一页",
        "nextPageLabel"=>"&gt; 下一页",
        "firstPageLabel"=>"&lt;&lt; 首页",
        "lastPageLabel"=>"&gt;&gt; 尾页",
        "maxButtonCount"=>5,
        "footer"=>"当前页数：".($data->pagination->currentPage+1)." 总页数：".$data->pagination->pageCount." 总记录数：".$data->pagination->itemCount
    )) ?>
	</div>
</div>

<?php if(Yii::app()->user->hasFlash('success'))
        echo "<script> art.dialog({
        id: 'dialogTest',
        title: '提示信息',
        time: 5,
        icon: 'succeed',
        content: '<b>操作成功！</b><br /><br />该消息5秒后自动消失！',
        button: [
            {
                name: '确定',
                focus: true
            }]
    });</script>" 

?><!-- 数据分页 -->
<!-- 脚本 -->
<script type="text/javascript">
    function deleteSelect(id){
        ajaxSubmitdeleteSelect(id,'<?php echo Yii::app()->createUrl('party/delete',array('id'=>0)) ?>');
    }
    function updateSelect(id){
        ajaxSubmitUpdateSelect(id,'<?php echo Yii::app()->createUrl('party/blackList',array('id'=>0)) ?>');
    }
    function canceSelect(id){
        ajaxSubmitUpdateSelect(id,'<?php echo Yii::app()->createUrl('party/cancelList',array('id'=>0)) ?>');
    }
    function floatSelect(id){
        ajaxSubmitUpdateSelect(id,'<?php echo Yii::app()->createUrl('party/checkParty',array('id'=>0)) ?>');
    }
     function sendSelect(id){
        ajaxSubmitUpdateSelect(id,'<?php echo Yii::app()->createUrl('party/sendMeg',array('id'=>0)) ?>');
    }
    function notTo(id){
        ajaxSubmitChangeParty(id,1,'<?php echo Yii::app()->createUrl('party/changeParty',array('id'=>0)) ?>');
    } 
    function haveTo(id){
        ajaxSubmitChangeParty(id,3,'<?php echo Yii::app()->createUrl('party/changeParty',array('id'=>0)) ?>');
    }   
    function cancelTo(id){
        ajaxSubmitChangeParty(id,0,'<?php echo Yii::app()->createUrl('party/changeParty',array('id'=>0)) ?>');
    }      
    
    function ajaxSubmitUpdateSelect(id,url){
        if(id==0){
            var ids=new Array();
            $('input[name="id[]"]').each(function(){
                if($(this).attr("checked"))
                    ids.push($(this).val());
            });
            id=ids;
        }
        art.dialog({
                lock: true,
                background: '#600',
                opacity: 0.6,
                content: '确认修改？',
                icon: 'warning',
                ok:function(){
                    $.ajax({
                        type:"POST",
                        dataType:"json",
                        data:{"id[]":id},
                        url:url,
                        success:function(json) {
                            if(json.result==0){
                                alert("操作成功");
                                location.reload();
                            }else if(json.result==1){
                                art.dialog({icon:'error',content:'操作数据失败。。。',time:1});
                            }else{
//                                location.href=; 
                                parent.location.replace("<?php echo Yii::app()->baseUrl?>/index.php/activityDetail/update/"+json.result); 
                            }
                        }
                    });
                },
                cancel: function(){}
     });
}
    function ajaxSubmitChangeParty(id,type,url){
        if(id==0){
            var ids=new Array();
            $('input[name="id[]"]').each(function(){
                if($(this).attr("checked"))
                    ids.push($(this).val());
            });
            id=ids;
        }
        art.dialog({
                lock: true,
                background: '#600',
                opacity: 0.6,
                content: '确认修改？',
                icon: 'warning',
                ok:function(){
                    $.ajax({
                        type:"POST",
                        dataType:"json",
                        data:{"id":id,'type':type},
                        url:url,
                        success:function(json) {
                            if(json.result==0){
                                alert("操作成功");
                                location.reload();
                            }else{
                                art.dialog({icon:'error',content:'操作数据失败。。。',time:1});
                            }
                        }
                    });
                },
                cancel: function(){}
     });
}
</script>
<!-- 脚本 -->
